using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading;
using Roslyn.Compilers;
using Roslyn.Compilers.Common;
using Roslyn.Compilers.CSharp;
using Roslyn.Services;
using Roslyn.Services.Editor;
using Analysis;

namespace TestabilityCodeIssues
{
    [ExportSyntaxNodeCodeIssueProvider("TestabilityCodeIssues", LanguageNames.CSharp, typeof(ConstructorDeclarationSyntax), typeof(MethodDeclarationSyntax))]
    class CodeIssueProvider : ICodeIssueProvider
    {
        private readonly PresentationHelper presentationHelper = new PresentationHelper();

        public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxNode node, CancellationToken cancellationToken)
        {
            var body = ((BaseMethodDeclarationSyntax)node).Body;

            if (body == null)
                return new List<CodeIssue>();

            return
                new ClassDependencies()
                    .GetDependencies(body, document)
                         .Select(d => new CodeIssue(CodeIssue.Severity.Warning, d.In.Span, "Testability warning: " + presentationHelper.TranslateWarning(d.Kind)));
        }

        #region Unimplemented ICodeIssueProvider members

        public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxToken token, CancellationToken cancellationToken)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxTrivia trivia, CancellationToken cancellationToken)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
